package com.jiuyun.servlet;
import com.jiuyun.dao.PersonalDao;
import com.jiuyun.dao.StudentaDao;
import com.jiuyun.dao.impi.PersonalDaoimpl;
import com.jiuyun.dao.impi.StudentaDaoimpl;
import com.jiuyun.entity.PerStudent;
import com.jiuyun.entity.PerTeacher;

import com.jiuyun.entity.PerUser;
import com.jiuyun.entity.Userrole;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@WebServlet("/personal/*")
public class PersonalServlet extends BaseServlet {
    PersonalDao dao = new PersonalDaoimpl();
    StudentaDao sdao = new StudentaDaoimpl();

    protected void find(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {
        System.out.println("查");
        List<PerUser> ulist = new ArrayList<>();
        List<PerTeacher> tlist = new ArrayList<>();
        List<PerStudent> slist = new ArrayList<>();
        HttpSession session = request.getSession();
        int id = Integer.parseInt(request.getParameter("id"));
        Userrole list=sdao.grxx(id);
        session.setAttribute("tlist", list);
        response.sendRedirect("/Eventstar/personal.jsp");
    }

    protected void update(HttpServletRequest request, HttpServletResponse response) throws IOException, SQLException {
        System.out.println("修改");
        int id = Integer.parseInt(request.getParameter("id"));
        String uname=request.getParameter("uname");
        String upass=request.getParameter("upass");
        System.out.println(id);
        HttpSession session = request.getSession();
            int num = dao.updateStudent(id,uname, upass);
            if (num == 0) {
                System.out.println("修改失败！");
            } else {
                System.out.println("修改成功！");
                response.sendRedirect("/Eventstar/personal/find?id="+id+"");
            }
    }

    protected void find1(HttpServletRequest request, HttpServletResponse response) throws IOException, SQLException {
        int id=Integer.parseInt(request.getParameter("id"));
        HttpSession session=request.getSession();
        List<Userrole> slist  = dao.findStu(id);
        session.setAttribute("slist", slist);
        response.sendRedirect("/Eventstar/update-personal.jsp");
    }
}